package com.menggudf.service.impl;

import com.menggudf.entity.MedicalTaboo;
import com.menggudf.mapper.MedicalTabooDao;
import com.menggudf.service.MedicalTabooService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (MedicalTaboo)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 16:58:30
 */
@Service("medicalTabooService")
public class MedicalTabooServiceImpl implements MedicalTabooService {
    @Resource
    private MedicalTabooDao medicalTabooDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public MedicalTaboo queryById(Integer id) {
        return this.medicalTabooDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param medicalTaboo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<MedicalTaboo> queryByPage(MedicalTaboo medicalTaboo, PageRequest pageRequest) {
        long total = this.medicalTabooDao.count(medicalTaboo);
        return new PageImpl<>(this.medicalTabooDao.queryAllByLimit(medicalTaboo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param medicalTaboo 实例对象
     * @return 实例对象
     */
    @Override
    public MedicalTaboo insert(MedicalTaboo medicalTaboo) {
        this.medicalTabooDao.insert(medicalTaboo);
        return medicalTaboo;
    }

    /**
     * 修改数据
     *
     * @param medicalTaboo 实例对象
     * @return 实例对象
     */
    @Override
    public MedicalTaboo update(MedicalTaboo medicalTaboo) {
        this.medicalTabooDao.update(medicalTaboo);
        return this.queryById(medicalTaboo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.medicalTabooDao.deleteById(id) > 0;
    }
}
